package com.xinli.business.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xinli.business.domain.FtMember;
import com.xinli.business.mapper.FtMemberMapper;
import com.xinli.business.service.IFtMemberService;
import com.xinli.common.utils.DateUtils;
import com.xinli.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 学员信息Service业务层处理
 *
 * @author ruoyi
 * @date 2025-03-18
 */
@Service
public class FtMemberServiceImpl extends ServiceImpl<FtMemberMapper, FtMember>  implements IFtMemberService
{
    @Autowired
    private FtMemberMapper ftMemberMapper;

    /**
     * 查询学员信息
     *
     * @param memberId 学员信息主键
     * @return 学员信息
     */
    @Override
    public FtMember selectFtMemberByMemberId(Long memberId)
    {
        return ftMemberMapper.selectFtMemberByMemberId(memberId);
    }

    /**
     * 查询学员信息列表
     *
     * @param ftMember 学员信息
     * @return 学员信息
     */
    @Override
    public List<FtMember> selectFtMemberList(FtMember ftMember)
    {
        return ftMemberMapper.selectFtMemberList(ftMember);
    }

    @Override
    public List<FtMember> selectFtMemberListApp(FtMember ftMember)
    {
        return ftMemberMapper.selectFtMemberListApp(ftMember);
    }


    /**
     * 新增学员信息
     *
     * @param ftMember 学员信息
     * @return 结果
     */
    @Override
    public int insertFtMember(FtMember ftMember)
    {
                ftMember.setCreateTime(DateUtils.getNowDate());
            return ftMemberMapper.insertFtMember(ftMember);
    }

    /**
     * 修改学员信息
     *
     * @param ftMember 学员信息
     * @return 结果
     */
    @Override
    public int updateFtMember(FtMember ftMember)
    {
                ftMember.setUpdateTime(DateUtils.getNowDate());
        return ftMemberMapper.updateFtMember(ftMember);
    }

    /**
     * 批量删除学员信息
     *
     * @param memberIds 需要删除的学员信息主键
     * @return 结果
     */
    @Override
    public int deleteFtMemberByMemberIds(Long[] memberIds)
    {
        return ftMemberMapper.deleteFtMemberByMemberIds(memberIds);
    }

    /**
     * 删除学员信息信息
     *
     * @param memberId 学员信息主键
     * @return 结果
     */
    @Override
    public int deleteFtMemberByMemberId(Long memberId)
    {
        return ftMemberMapper.deleteFtMemberByMemberId(memberId);
    }


    @Override
    public  Boolean  isRepeatPhone(String phone,String phone1,String phone2,String unionId){
        QueryWrapper<FtMember> ftMemberQueryWrapper= new QueryWrapper<>();
        // 判断 phone 或  phone1 或 phone2 是否已经存在
        if(StringUtils.isNotEmpty(phone)){
            ftMemberQueryWrapper.or().eq("phone",phone);
            ftMemberQueryWrapper.or().eq("phone1",phone);
            ftMemberQueryWrapper.or().eq("phone2",phone);
        }
        if(StringUtils.isNotEmpty(phone1)){
            ftMemberQueryWrapper.or().eq("phone",phone1);
            ftMemberQueryWrapper.or().eq("phone1",phone1);
            ftMemberQueryWrapper.or().eq("phone2",phone1);
        }
        if(StringUtils.isNotEmpty(phone2)){
            ftMemberQueryWrapper.or().eq("phone",phone2);
            ftMemberQueryWrapper.or().eq("phone1",phone2);
            ftMemberQueryWrapper.or().eq("phone2",phone2);
        }
        ftMemberQueryWrapper.ne("union_id",unionId);
        long count = this.count(ftMemberQueryWrapper);
        return count>0;
    }
    @Override
    public  Boolean  isRepeatPhoneById(String phone,String phone1,String phone2,String id){
        QueryWrapper<FtMember> ftMemberQueryWrapper= new QueryWrapper<>();
        // 判断 phone 或  phone1 或 phone2 是否已经存在
        ftMemberQueryWrapper.or().eq("phone",phone);
        ftMemberQueryWrapper.or().eq("phone",phone1);
        ftMemberQueryWrapper.or().eq("phone",phone2);
        ftMemberQueryWrapper.or().eq("phone1",phone);
        ftMemberQueryWrapper.or().eq("phone1",phone1);
        ftMemberQueryWrapper.or().eq("phone1",phone2);
        ftMemberQueryWrapper.or().eq("phone2",phone);
        ftMemberQueryWrapper.or().eq("phone2",phone1);
        ftMemberQueryWrapper.or().eq("phone2",phone);
        ftMemberQueryWrapper.ne("member_id",id);
        long count = this.count(ftMemberQueryWrapper);
        return count>0;
    }


}
